package com.xii.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xii.eduservice.entity.EduCourse;
import com.xii.eduservice.entity.EduTeacher;
import com.xii.eduservice.mapper.EduTeacherMapper;
import com.xii.eduservice.service.EduTeacherService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author xhjava
 * @since 2022-01-16
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    /**
     * 使用原生的分页方法
     * @param teacherPage
     * @return
     */
    @Override
    public Map<String, Object> getTeacherFrontList(Page<EduTeacher> teacherPage) {
        //mp 进行查询所有数据
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("sort");
        //进行分页数据查询  会返回到teacherPage中
        this.baseMapper.selectPage(teacherPage,queryWrapper);

        List<EduTeacher> records = teacherPage.getRecords();
        long current = teacherPage.getCurrent();  //当前页
        long pages = teacherPage.getPages();        //总页数
        long size = teacherPage.getSize();  //当前页记录数
        long total = teacherPage.getTotal();    //总记录数
        boolean hasNext = teacherPage.hasNext();    //是否有下一页
        boolean hasPrevious = teacherPage.hasPrevious(); //是否有上一页

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }

}
